package com.linjiahao.servicebase.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName RabbitConfig
 * @Description: rabbit配置类
 * @Author linjiahao
 * @Date 26/12/2021
 **/
@Configuration
public class RabbitConfig {


    /**
     * 创建人：张博
     * 时间：2018/3/5 上午10:48
     * @apiNote 定义自动删除匿名队列
     */
    @Bean
    public FanoutExchange fanoutExchange() {
        return new FanoutExchange("netty-chat");
    }

    /**
     * @apiNote 定义自动删除匿名队列
     */
    @Bean
    public Queue autoDeleteQueue0() {
        return new AnonymousQueue();
    }

    /**
     * @apiNote 定义自动删除匿名队列
     */
    @Bean
    public Queue autoDeleteQueue1() {
        return new AnonymousQueue();
    }

    /**
     * @param fanoutExchange 广播交换器
     * @param autoDeleteQueue0 自动删除队列
     * @apiNote 把队列绑定到广播交换器
     * @return Binding
     */
    @Bean
    public Binding binding0(FanoutExchange fanoutExchange, Queue autoDeleteQueue0) {
        return BindingBuilder.bind(autoDeleteQueue0).to(fanoutExchange);
    }

    /**
     * @param fanoutExchange 广播交换器
     * @param autoDeleteQueue1 自动删除队列
     * @apiNote 把队列绑定到广播交换器
     * @return Binding
     */
    @Bean
    public Binding binding1(FanoutExchange fanoutExchange, Queue autoDeleteQueue1) {
        return BindingBuilder.bind(autoDeleteQueue1).to(fanoutExchange);
    }

}
